package com.qf.smartplatform.service.impl;

import com.qf.smartplatform.constans.ResultCode;
import com.qf.smartplatform.exceptions.AddException;
import com.qf.smartplatform.mapper.HumitureMapper;
import com.qf.smartplatform.pojo.SysHumiture;
import com.qf.smartplatform.service.HumitureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Date;

/*** @author Tgb
 * @version V1.0
 * @Project smartplatform
 * @Package com.qf.smartplatform.service.impl
 * @Description:
 * @Date 2022/9/14 21:59
 */
@Component
public class HumitureServiceImpl implements HumitureService {
    private HumitureMapper humitureMapper;
    @Autowired
    public void setHumitureMapper(HumitureMapper humitureMapper) {
        this.humitureMapper = humitureMapper;
    }

    @Override
    @EventListener
    public void addHumiture(SysHumiture humiture) {
        Assert.isTrue(humiture==null&&humiture.isEmpty(),()->{
            throw new AddException("添加数据不完整", ResultCode.PARAM_CONTENT_EMPTY);
        });
        humiture.setUploadTime(new Date());
        humitureMapper.addHumiture(humiture);
    }
}
